from django.shortcuts import render
from django.http import HttpResponse,HttpResponse
from django.shortcuts import redirect
from app01.models import user
# Create your views here.
def new(request):
    return  render(request,"new.html")

# def orm(request):
#     user.objects.create(name="杨弟",classes="1",gender='男')
#     user.objects.create(name="班主任",classes="2",gender='女')
#     user.objects.create(name="松",classes="3",gender='男')
#     return HttpResponse("操作成功")


# def orm(request):
#     # 删除id所对应的数据
#     user.objects.filter(id=1).delete()
#     # # 删除所有
#     # user.objects.filter().delete()
#     return HttpResponse("操作成功")


def orm(request):
    user_obj = user.objects.filter(id=2).first()

    if user_obj:
        # 在响应中显示用户信息
        user_info = f"姓名: {user_obj.name}, 班级: {user_obj.classes}, 性别: {user_obj.gender}"
        return HttpResponse(user_info)
    else:
        return HttpResponse("用户不存在")
# def orm(request):
#     # 修改数据
#     user.objects.all().update(gender="男")
#     # user.objects.filter(name="").update()
#     return HttpResponse("操作成功")